<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var data = {
            name: 'andy',
            age: 20
        }
        var str = '<div>我是{{name}}今年{{  age  }}岁了</div>'
        var zz = /{{\s*([a-zA-Z]+)\s*}}/


        var re = null
        while (re = zz.exec(str)) {
            // 将正则匹配、提取出的值  替换成数据值  
            str = str.replace(re[0], data[re[1]])

        }
        console.log(str);

    </script>
</body>

</html>